package com.example.zhu95.mytimber.listener;

import android.widget.SeekBar;

import com.example.zhu95.mytimber.MyApplication;
import com.example.zhu95.mytimber.utils.DBHelper;

import static com.example.zhu95.mytimber.ConstantValue.PlayMusicCmd_CurrentPosition;
import static com.example.zhu95.mytimber.activity.BaseActivity.currentPosition;
import static com.example.zhu95.mytimber.activity.BaseActivity.songid;

/**
 * @author zhu95
 * @date 2018/3/20 22:49
 */
public class SeekBarChangeListener implements SeekBar.OnSeekBarChangeListener {
    private CallBack callBack;

    public SeekBarChangeListener(CallBack callBack) {
        this.callBack = callBack;
    }

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        //表示是由用户从界面触发
        if (fromUser) {
            currentPosition = progress;
            DBHelper.recordCurrentPotision(currentPosition);
            callBack.updateOtherUI(progress);
            MyApplication.sendPlayMusicCmdBroadcast(songid, "", PlayMusicCmd_CurrentPosition, progress);
        }
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {

    }

    public interface CallBack {
        void updateOtherUI(int position);
    }
}
